<?php

namespace App\Console\Commands;

use App\Library\Logic\AuctionOrderLogic;
use Illuminate\Console\Command;

class AuctionPayEndCommand extends Command
{
    /**
     * 取消超过拍卖付款时间订单
     *
     * @var string
     */
    //protected $signature = 'command:auctionPayEnd {serialNumber}';
    protected $signature = 'command:auctionPayEnd';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        $list = AuctionOrderLogic::query()->where('status', 1)->get();
        if (is_null($list)) return;
        foreach ($list as $auctionOrder) {
            if (now()->lt(now()->parse($auctionOrder->pay_end_at))) continue;
            else if ($auctionOrder->status !== 1) continue;
            $upd = [
                'status_cancel' => 1,
                'status' => 0,
                'status_over_time' => 1,
                'cancel_at' => now(),
            ];
            AuctionOrderLogic::query()->where('id', $auctionOrder->id)->update($upd);
        }
    }

    /**
     * Execute the console command.
     */
    /*public function handle(): void
    {
        $serialNumber = $this->argument('serialNumber');
        if (empty($serialNumber) || strlen($serialNumber) !== 20) return;
        $auctionOrder = AuctionOrderLogic::findBySerialNumber($serialNumber);
        if (is_null($auctionOrder)) return;
        else if (now()->lt(now()->parse($auctionOrder->pay_end_at))) return;
        else if ($auctionOrder->status !== 1) return;
        $auctionOrder->status_cancel = 1;
        $auctionOrder->cancel_at = now();
        $auctionOrder->status = 0;
        $auctionOrder->status_over_time = 1;
        $auctionOrder->save();
    }*/
}
